<template>
  <div>
    <p class="pinformation">统计信息</p>
    <el-form :model="form" ref="formRef" label-width="80">
      <el-row>
        <el-form-item label="现场原始记录总数：" label-width="130">
          {{ form.tableCount }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="已填报数："> {{ form.writeCount }} </el-form-item>
        <el-form-item style="margin-left: 10px" label="未填报数："> {{ form.notWriteCount }} </el-form-item>
        <el-form-item style="margin-left: 10px" label="已复核数："> {{ form.reviewCount }} </el-form-item>
        <el-form-item style="margin-left: 10px" label="未复核数："> {{ form.notReviewCount }} </el-form-item>
        <el-form-item style="margin-left: 10px" label="已审核数："> {{ form.approveCount }} </el-form-item>
        <el-form-item style="margin-left: 10px" label="未审核数："> {{ form.notApproveCount }} </el-form-item>
      </el-row>
    </el-form>
    <p class="pinformation">现场原始记录搜索</p>
    <el-form ref="queryRef" label-width="80" :model="queryParams" :inline="true">
          <el-form-item label="采样人：" prop="nickName" label-width="60">
            <el-input @keyup.enter="handleQuery" clearable maxlength="100" placeholder="请输入采样人"
              v-model="queryParams.nickName" />
          </el-form-item>
          <el-form-item label="检测类别：" prop="jclbId">
            <el-select v-model="queryParams.jclbId" style="width: 100%" filterable clearable>
              <el-option v-for="item in jclbTypeList" :key="item.jclbId"
                :label="item.jclbName !== '' ? item.jclbName : item.jclbGroupName" :value="item.jclbId" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="resetBtn" @click="resetQuery">重置</el-button>
          </el-form-item>
    </el-form>
    <el-row>
      <p class="pinformation">现场原始记录列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table border :data="tableData" ref="dataTableRef" v-loading="loading">
      <el-table-column align="center" show-overflow-tooltip label="标题" prop="title" />
      <el-table-column align="center" show-overflow-tooltip label="检测类别" prop="jclbName" width="100" />
      <el-table-column align="center" show-overflow-tooltip label="原始记录名称" prop="tableName" width="230" />
      <el-table-column align="center" show-overflow-tooltip label="采样人" prop="writeName" width="120" />
      <el-table-column align="center" show-overflow-tooltip label="填报时间" prop="writeTime" width="140" />
      <el-table-column align="center" show-overflow-tooltip label="复核人" prop="reviewName" width="90" />
      <el-table-column align="center" show-overflow-tooltip label="复核时间" prop="reviewTime" width="140" />
      <el-table-column align="center" show-overflow-tooltip label="审核人" prop="approveName" width="90" />
      <el-table-column align="center" show-overflow-tooltip label="审核时间" prop="approveTime" width="140" />
      <el-table-column show-overflow-tooltip label="操作" align="center" width="70" fixed="right">
        <template #default="scope">
          <el-button link type="success" @click="handleTx(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :class="'el-dialog-theme3'" v-model="show" title="查看原始记录表详情" fullscreen>
      <formList  ref="formListRef" />
    </el-dialog>
  </div>
</template>

<script setup>
import { getYsjlbFrom, getYsjlbList } from "@/api/taskProgressDetails/index";
import formList from "@/views/cyCheck/public/common/formList";
import { projectListJclb } from "@/api/store/jclb";
const { proxy } = getCurrentInstance();
const form = ref({});
const queryParams = ref({ pageNum: 1, pageSize: 10 });
const tableData = ref([]);
const total = ref(0);
const projectId = ref("");
const show = ref(false)
const loading = ref(false)
const heightParams = ref([{ tableName: "data", bottomHeight: 21 }]);
const formListRef = ref(null)
const jclbTypeList = ref([])

function getForm(val) {
  projectId.value = val;
  queryParams.value.projectId = val;
  getYsjlbFrom(val).then((res) => {
    form.value = res.data;
  });
  projectListJclb({ projectId: val }).then((res) => {
    jclbTypeList.value = res.data;
  });
  getList()
}

function getList() {
  loading.value = true
  getYsjlbList(queryParams.value).then((res) => {
    tableData.value = res.rows;
    total.value = res.total;
    loading.value = false
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

function handleTx(row) {
  show.value = true
  nextTick(() => {
    formListRef.value.getInfo(row.taskId)
  })
}

defineExpose({
  getForm,
});

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "data", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "data", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);
</script>

<style></style>
